<?php
if (!defined("MCTDESIGN")) die("# ");
if (isset($_POST['save'])) {
	if (isset($_SESSION["post_time"])&&($_SESSION["post_time"]>=time()-$time_limit))
		{
			$html_body = _html_trans("Để tránh việc food database, sau $time_limit giây nữa bạn hãy thực hiện việc cập nhật.");
			return false;
		}
	$_SESSION["post_time"] = time();
	$txtShopName = isset($_POST["txtShopName"]) ? fixquotes(stripslashes($_POST["txtShopName"])) : "";
	$txtAddress = isset($_POST["txtAddress"]) ? fixquotes(stripslashes($_POST["txtAddress"])) : "";
	$txtFax = isset($_POST["txtFax"]) ? fixquotes(stripslashes($_POST["txtFax"])) : "";
	$txtEmail = isset($_POST["txtEmail"]) ? fixquotes(stripslashes($_POST["txtEmail"])) : "";
	$txtYms = isset($_POST["txtYms"]) ? fixquotes(stripslashes($_POST["txtYms"])) : "";
	$txtPhone = isset($_POST["txtPhone"]) ? fixquotes(stripslashes($_POST["txtPhone"])) : "";
	$txtAbout = isset($_POST["txtAbout"]) ? fixquotes(stripslashes($_POST["txtAbout"])) : "";
	$txtService = isset($_POST["txtService"]) ? fixquotes(stripslashes($_POST["txtService"])) : "";
	$txtTerm = isset($_POST["txtTerm"]) ? fixquotes(stripslashes($_POST["txtTerm"])) : "";
	$txtContact = isset($_POST["txtContact"]) ? fixquotes(stripslashes($_POST["txtContact"])) : "";
	$txtJobs = isset($_POST["txtJobs"]) ? fixquotes(stripslashes($_POST["txtJobs"])) : "";
	$txtUsd = isset($_POST["txtUsd"]) ? intval(stripslashes($_POST["txtUsd"])) : "";
    $txtShopUrl = isset($_POST['txtShopUrl']) ? fixquotes(stripslashes($_POST["txtShopUrl"])) : "";
    // isPost congfig email 
    $txtShop_Smtpsever = isset($_POST['txtShop_Smtp_Server']) ? fixquotes(stripslashes($_POST["txtShop_Smtp_Server"])) : "";
    $txtShop_SmtpPort = isset($_POST['txtShop_Smtp_Port']) ? intval(stripslashes($_POST["txtShop_Smtp_Port"])) : "";
    $txtShop_SmtpUname = isset($_POST['txtShop_Smtp_User']) ? fixquotes(stripslashes($_POST["txtShop_Smtp_User"])) : "";
    $txtShop_SmtpPass = isset($_POST['txtShop_Smtp_Pass']) ? fixquotes(stripslashes($_POST["txtShop_Smtp_Pass"])) : "";
	/**/
    
    // tiitle category
    $txt_chothuexe = isset($_POST["txt_chothuexe"]) ? fixquotes(stripslashes($_POST["txt_chothuexe"])) : "";
    $txt_khachsankm = isset($_POST["txt_khachsankm"]) ? fixquotes(stripslashes($_POST["txt_khachsankm"])) : "";
    $txt_lichkh = isset($_POST["txt_lichkh"]) ? fixquotes(stripslashes($_POST["txt_lichkh"])) : "";
    // end category
	$txtBaogia = isset($_FILES['txtBaogia']['name'] ) ? $_FILES['txtBaogia']['name'] : '';
	$txtBaogia_tmp = isset($_FILES['txtBaogia']['tmp_name'] ) ? $_FILES['txtBaogia']['tmp_name'] : '';
    if (!empty($txtBaogia)) {
		$start = strpos($txtBaogia,".");
		$type = substr($txtBaogia,$start,strlen($txtBaogia));
		if ((strtolower($type)==".doc") || (strtolower($type)==".xls")){
			$date=time();
			$filename = $date."_".$txtBaogia;
			$file_upload = "./_uploads/baogia/".$filename;
            //echo $file_upload;die();
			if ( !(copy($txtBaogia_tmp, $file_upload)) ) die("Cannot upload files.");
		}
        $mysql->query("UPDATE ".$tb_fix."_config SET config_values='".$file_upload."' WHERE config_id='16'");
	}
	/* ------------------------------------------------------------------------------------------------ */
    // title category
    $mysql->query("UPDATE ".$tb_fix."_config SET config_values='".trim($txt_lichkh)."' WHERE config_id='24'");
    $mysql->query("UPDATE ".$tb_fix."_config SET config_values='".trim($txt_khachsankm)."' WHERE config_id='23'");
    $mysql->query("UPDATE ".$tb_fix."_config SET config_values='".trim($txt_chothuexe)."' WHERE config_id='22'");    
    
    // config mail
    $mysql->query("UPDATE ".$tb_fix."_config SET config_values='".trim($txtShop_Smtpsever)."' WHERE config_id='18'");
    $mysql->query("UPDATE ".$tb_fix."_config SET config_values='".trim($txtShop_SmtpPort)."' WHERE config_id='19'");
    $mysql->query("UPDATE ".$tb_fix."_config SET config_values='".trim($txtShop_SmtpUname)."' WHERE config_id='20'");
    $mysql->query("UPDATE ".$tb_fix."_config SET config_values='".trim($txtShop_SmtpPass)."' WHERE config_id='21'");
    // update config mail
	$mysql->query("UPDATE ".$tb_fix."_config SET config_values='".$txtShopName."' WHERE config_id='2'");
	$mysql->query("UPDATE ".$tb_fix."_config SET config_values='".$txtAddress."' WHERE config_id='3'");
	$mysql->query("UPDATE ".$tb_fix."_config SET config_values='".$txtFax."' WHERE config_id='4'");
	$mysql->query("UPDATE ".$tb_fix."_config SET config_values='".$txtEmail."' WHERE config_id='5'");
	$mysql->query("UPDATE ".$tb_fix."_config SET config_values='".$txtYms."' WHERE config_id='8'");
	$mysql->query("UPDATE ".$tb_fix."_config SET config_values='".$txtPhone."' WHERE config_id='9'");
	$mysql->query("UPDATE ".$tb_fix."_config SET config_values='".$txtAbout."' WHERE config_id='10'");
	$mysql->query("UPDATE ".$tb_fix."_config SET config_values='".$txtTerm."' WHERE config_id='12'");
	$mysql->query("UPDATE ".$tb_fix."_config SET config_values='".$txtUsd."' WHERE config_id='14'");
	$mysql->query("UPDATE ".$tb_fix."_config SET config_values='".$txtJobs."' WHERE config_id='15'");	
    $mysql->query("UPDATE ".$tb_fix."_config SET config_values='".$txtShopUrl."' WHERE config_id='1'");
	/* ------------------------------------------------------------------------------------------------ */
	$html_body = _html_trans("Đã cập nhật cấu hình cho website thành công!");
	return false;
}

function _html_Config()
{
	global $mysql, $tb_fix,$temp;
	$temp_body = $temp;
	$q = $mysql->query("SELECT * FROM ".$tb_fix."_config WHERE config_name!=''");
	while ($r = $mysql->fetch_array($q)) {

		$temp_body->assign( "".$r['config_name']."", "".$r['config_values']."" );
	}
    $temp_body->assign("breakcum",breakcum("Cập nhật thông tin "));
	$_html = $temp_body->fetch( '_adm_config.mct' );
	return $_html;
}
$html_body = _html_Config();
?>